//
//  ViewController.m
//  30205
//
//  Created by student on 16/4/6.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
#import "DrawView.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet DrawView *drawview;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSArray *list = @[@{@"text":@"iOS",@"percent":@.40},
                      @{@"text":@"Android",@"percent":@.55},
                      @{@"text":@"其他",@"percent":@.05}];
    self.drawview.list=list;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.drawview.type=!self.drawview.type;
    NSMutableArray *marr=[NSMutableArray array];
    int all=0;
    for(int i=0;i<10;i++)
    {
        CGFloat percent=arc4random_uniform(80);
        if(all+percent>100)
        {
            percent=100-all;
        }
        NSDictionary *dict=@{ @"text":[NSString stringWithFormat:@"类型%i",i],
                              @"percent":@(percent/100.0)};
        [marr addObject:dict];
        all+=percent;
        if(all>=100)
        {
            break;
        }
    }
    self.drawview.list=marr;
}


@end
